home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / screen-resolution-extra / policy-dontzap.py next >
Encoding:
Python Source  |  2009-04-06  |  2.3 KB  |  76 lines

  1. # -*- coding: utf-8 -*-
  2. ## Copyright (C) 2001-2008 Alberto Milone <albertomilone@alice.it>
  3.  
  4. ## This program is free software; you can redistribute it and/or modify
  5. ## it under the terms of the GNU General Public License as published by
  6. ## the Free Software Foundation; either version 2 of the License, or
  7. ## (at your option) any later version.
  8.  
  9. ## This program is distributed in the hope that it will be useful,
  10. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ## GNU General Public License for more details.
  13.  
  14. ## You should have received a copy of the GNU General Public License
  15. ## along with this program; if not, write to the Free Software
  16. ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19. import gtk, gobject, sys, dbus, logging
  20. import ScreenResolution
  21. from ScreenResolution.policykit import PolicyKitAuthentication
  22.  
  23. POLICY_KIT_ACTION = 'com.ubuntu.screenresolution.mechanism.dontzap'
  24. SERVICE_NAME   = 'com.ubuntu.ScreenResolution.Mechanism'
  25. OBJECT_PATH    = '/'
  26. INTERFACE_NAME = 'com.ubuntu.ScreenResolution.Mechanism'
  27. usage = 'python policy-dontzap.py --enable'
  28.  
  29. import os
  30. import sys
  31.  
  32.  
  33. def get_dontzap_service(widget=None):
  34.     '''
  35.     returns a dbus interface to the screenresolution mechanism
  36.     '''
  37.     policy_auth = PolicyKitAuthentication()    
  38.  
  39.     granted = policy_auth.obtain_authorization(POLICY_KIT_ACTION, widget)
  40.     logging.debug("granted = %s" % granted)
  41.  
  42.     if not granted:
  43.         return None
  44.     
  45.     service_object = dbus.SystemBus().get_object(SERVICE_NAME, OBJECT_PATH)
  46.     service = dbus.Interface(service_object, INTERFACE_NAME)
  47.  
  48.     return service
  49.  
  50. def main(enable):
  51.     if enable not in ['--enable', '--disable']:
  52.         logging.error("called with wrong arguments = %s" % str(enable))
  53.         return False
  54.     
  55.     conf = get_dontzap_service()
  56.     if not conf:
  57.         # dbus_cant_connect
  58.         logging.error("cannot connect to dbus service")
  59.         sys.exit(1)
  60.     logging.debug("setting dontzap to %s" % enable)
  61.     exit_code = conf.setDontZap(enable)
  62.     logging.debug("exit status: %d" % exit_code)
  63.  
  64.     # All went well if exit_code == 0
  65.     return exit_code
  66.  
  67.  
  68. if __name__ == "__main__":
  69.     if len(sys.argv) > 1:
  70.         operation_status = main(sys.argv[1])
  71.     else:
  72.         operation_status = 1
  73.     
  74.     sys.exit(operation_status)
  75.  
  76.